<script setup lang="ts">
// import { onMounted, onUnmounted, ref } from 'vue';
import { useWindowSize } from '@vueuse/core';
import DoctorCard from './DoctorCard.vue';
// import type { DoctorList, DoctorType } from '@/types/consult'
import { onMounted, ref } from 'vue';
import { getDoctorPage } from '@/apis/consult';
const { width } = useWindowSize()
// 以下的代码等价于 控制台安装 pnpm add @vueuse/core --> 导入它import { useWindowSize } from '@vueuse/core'    const { width } = useWindowSize()
// const width = ref(0)
// const handleResize = () =>{width.value = window.innerWidth}
// onMounted(()=>{
//   handleResize()
//   window.addEventListener('resize',handleResize)
// })
// onUnmounted(()=>{
//   handleResize()
//   window.removeEventListener('resize',handleResize)
// })
const list = ref<any>([])
const loadData = async () => {
  const res = await getDoctorPage({ current: 1, pageSize: 5 })
  // console.log(res.data.rows)
  list.value = res.data.rows
}
onMounted(() => { loadData() })
</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件 -->
      <van-swipe :width="150 / 375 * width" :show-indicators="false" :loop="false">
        <van-swipe-item v-for="item in list" :key="item.id">
          <!-- {{ item }} -->
          <doctor-card :item="item" />
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;

  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;

    >a {
      color: var(--cp-tip);
    }
  }

  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>